package www.openteam.com.tool;

import android.app.Service;
import android.content.Context;
import android.os.Vibrator;
import android.view.animation.Animation;
import android.view.animation.CycleInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.EditText;


/**
 * Created by kylin on 2017/5/3.
 */

public class EditTextShakeTool {
    //震动动画
    private Animation shakeAnimation;

    //插值器
    private CycleInterpolator cycleInterpolator;

    //振动器
    private Vibrator shakeVibrator;

    public EditTextShakeTool(Context context) {

        //初始化振动器
        shakeVibrator = (Vibrator) context.getSystemService(Service.VIBRATOR_SERVICE);

        //初始化动画
        shakeAnimation = new TranslateAnimation(0, 0, 20, 0);

        //初始化插值器
        cycleInterpolator = new CycleInterpolator(5);

        shakeAnimation.setInterpolator(cycleInterpolator);
    }


    public void shake(EditText... editText) {
        for (EditText et : editText) {
            et.startAnimation(shakeAnimation);
        }

        shakeVibrator.vibrate(new long[]{0, 500}, -1);
    }
}
